package 代码随想2._5双指针法;

/**
 * @author XXX
 * @date 2024-01-17 15:45
 */

import 代码随想2._2链表.ListNode;

/**
 * https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/description/
 */
public class _7链表相交 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode p1 = headA;
        ListNode p2 = headB;
        while (p1!=p2){
            p1 = p1!=null?p1.next:headB;
            p2 = p2!=null?p2.next:headA;
        }
        return p1==null?null:p1;
    }
}
